package cn.jzq.mysoul.yourname.util;

import org.apache.commons.lang3.StringUtils;

/**
 * 异步提交后返回的内容
 * @author 蒋正强
 */
public class ResultJson
{
	/**
	 * 状态,1,成功，0.失败
	 */
	private String status = "1";

	private Integer code = 200;
	
	/**
	 * 简单的错误信息
	 */
	private String errorMessage = "";
	
	/**
	 * 业务数据
	 */
	private Object data;

	public static ResultJson success()
    {
        return new ResultJson();
    }

    public static ResultJson success(Object data)
    {
        ResultJson resultJson = new ResultJson();
        if (data != null)
            resultJson.setData(data);

        return resultJson;
    }

    public static ResultJson error(Integer errorCode, String errorMessage)
    {
        ResultJson resultJson = new ResultJson();
        resultJson.setStatus("0");

        if (errorCode != null)
            resultJson.setCode(errorCode);

        if (StringUtils.isNotBlank(errorMessage))
            resultJson.setErrorMessage(errorMessage);
        else
            resultJson.setErrorMessage("系统错误");

        return resultJson;
    }

	public String getStatus()
	{
		return status;
	}

	public void setStatus(String status)
	{
		this.status = status;
	}

	public String getErrorMessage()
	{
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage)
	{
		this.errorMessage = errorMessage;
	}

	public Object getData()
	{
		return data;
	}

	public void setData(Object data)
	{
		this.data = data;
	}

    public Integer getCode()
    {
        return code;
    }

    public void setCode(Integer code)
    {
        this.code = code;
    }
}
